// 用户注册数据管理
const mongoose = require('mongoose')
const Schema = mongoose.Schema

// 实例化用户数据模板
const SchemaUser = new Schema({
  name: {
    type: String,
    required: true
  },
  passd: {
    type: String,
    required: true
  },
  date: {
    type: Number,
    default: new Date().getTime() // 默认创建日期为提交时的日期
  },
  id: {
    type: Number
  },
  token: {
    type: String,
    required: true
  },
  token_time: {
    type: Number,
    default: new Date().getTime() // 默认创建日期为提交时的日期
  },
})

// 实例化用户ID集合，用于关联和生成用户id
const SchemaID = new Schema({
  id: {
    type: Number,
  },
  name: {
    type: String
  },
  date: {
    type: Number,
    default: new Date().getTime()
  }
})

// 创建模板
const Ids = mongoose.model('ids', SchemaID)
const User = mongoose.model('users', SchemaUser)

// 输出
module.exports = {
  User: User,
  Ids: Ids
}
